package actions;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

public class GoldPriceAct implements Action {

	public static final String cmd="gold";
	final String cmd1 = "gold on";
	final String cmd2 = "gold off";
	boolean isOn=false;


	@Override
	public boolean checkCmd(String cmd) {
		if(cmd.equals(cmd1)){
			isOn=true;
			return true;
		}else if(cmd.equals(cmd2)){
			isOn=false;
			return true;
		}else return false;
	}
	@Override
	public void setHandles(Object... hdls) {
		// TODO Auto-generated method stub

	}

	@Override
	public Object call() throws Exception {
		if(isOn){
			
		}else{
			
		}
		return null;
	}

	
	private ExecutorService  executor=java.util.concurrent.Executors.newFixedThreadPool(1);
	class Task implements Callable {

		@Override
		public Object call() throws Exception {
			try {
				URL url = new URL(
						"http://www.xignite.com/xmetals.asmx/GetLastLondonFixing?Type=LondonGold&Currency=USD");
				URLConnection conn = url.openConnection();
				conn.setRequestProperty("User-Agent", "firefox");
				InputStream is = conn.getInputStream();
				StringBuffer recStr = new StringBuffer();
				byte[] rcvBuf = new byte[1024];
				int rcvPos = 0;
				int rcvCount = 0;
				while ((rcvCount = is.read(rcvBuf, rcvPos, rcvBuf.length
						- rcvPos)) > 0) {
					rcvPos += rcvCount;
					for (int i = 0; i < rcvCount; i++)
						recStr.append((char) rcvBuf[i]);
				}
				is.close();
				return recStr.toString();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return "";
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return "";
			}

		}

	}
	

}
